Email Summary Agent

工作流概述

这是一个包含9个节点的复杂工作流,主要用于自动化处理各种任务。

工作流源代码

下载
{
  "id": "M8oLW9Qd59zNJzg2",
  "meta": {
    "instanceId": "1abe0e4c2be794795d12bf72aa530a426a6f87aabad209ed6619bcaf0f666fb0",
    "templateCredsSetupCompleted": true
  },
  "name": "Email Summary Agent",
  "tags": [
    {
      "id": "G1v7CnFpOHsReVhM",
      "name": "Product",
      "createdAt": "2025-01-13T17:04:34.969Z",
      "updatedAt": "2025-01-13T17:04:34.969Z"
    },
    {
      "id": "RagrXIh5iBDseqvj",
      "name": "AI",
      "createdAt": "2025-01-09T09:18:12.756Z",
      "updatedAt": "2025-01-09T09:18:12.756Z"
    },
    {
      "id": "Yg2lfYteJZAoIeaC",
      "name": "Building blocks",
      "createdAt": "2025-01-13T17:05:49.788Z",
      "updatedAt": "2025-01-13T17:05:49.788Z"
    },
    {
      "id": "ZuS1C3NpE8uBlFq4",
      "name": "Finance",
      "createdAt": "2025-01-13T17:05:03.996Z",
      "updatedAt": "2025-01-13T17:05:03.996Z"
    },
    {
      "id": "aqlZb2qfWiaT4Xr5",
      "name": "IT Ops",
      "createdAt": "2025-01-03T12:20:11.917Z",
      "updatedAt": "2025-01-03T12:20:11.917Z"
    },
    {
      "id": "fX8hRnEv4D8sLSzF",
      "name": "OpenAI",
      "createdAt": "2025-01-09T09:18:12.757Z",
      "updatedAt": "2025-01-09T09:18:12.757Z"
    },
    {
      "id": "j1qBXzFADkR3sHSa",
      "name": "Marketing",
      "createdAt": "2025-01-13T17:03:54.468Z",
      "updatedAt": "2025-01-13T17:03:54.468Z"
    },
    {
      "id": "x3OVvOuZkLx1hYpW",
      "name": "Support",
      "createdAt": "2025-01-13T17:05:40.900Z",
      "updatedAt": "2025-01-13T17:05:40.900Z"
    },
    {
      "id": "xBOhq1kP3lza5ajE",
      "name": "HR",
      "createdAt": "2025-01-13T17:04:57.045Z",
      "updatedAt": "2025-01-13T17:04:57.045Z"
    },
    {
      "id": "yy04JQqCaXepPdSa",
      "name": "Project Management",
      "createdAt": "2024-10-30T18:27:57.309Z",
      "updatedAt": "2024-10-30T18:27:57.309Z"
    },
    {
      "id": "zJaZorWWcGpTp35U",
      "name": "DevOps",
      "createdAt": "2025-01-03T12:19:34.273Z",
      "updatedAt": "2025-01-03T12:19:34.273Z"
    }
  ],
  "nodes": [
    {
      "id": "94c09c05-539b-452e-83b7-0a029bbe6b7f",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -120,
        -140
      ],
      "parameters": {
        "width": 248.47086922498647,
        "height": 314.47468983163634,
        "content": "- Starts the workflow every day at 7 AM.
- Adjust the time if you want the workflow to run at a different hour."
      },
      "typeVersion": 1
    },
    {
      "id": "5e5cbc87-5c01-438b-a1c0-e8468d3ee20b",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        160,
        -137.04548301590512
      ],
      "parameters": {
        "width": 213.36643278764896,
        "height": 313.40934714314244,
        "content": "Fetches all emails received in the past 24 hours from the email address"
      },
      "typeVersion": 1
    },
    {
      "id": "9a82f5e9-7d0b-430f-9dbb-d8ae0b129dad",
      "name": "Daily 7AM Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -40,
        0
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 7
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "dd3e4b10-187b-45ce-b999-f0143e5af134",
      "name": "Fetch Emails - Past 24 Hours",
      "type": "n8n-nodes-base.gmail",
      "position": [
        220,
        0
      ],
      "webhookId": "20f1d11d-8a69-43f3-9323-33eaf1b3b600",
      "parameters": {
        "filters": {
          "q": "={{ 
  (() => {
    const yesterday = new Date();
    yesterday.setDate(yesterday.getDate() - 1);
    return `isb.quantana@quantana.in after:${yesterday.getFullYear()}/${(yesterday.getMonth() + 1).toString().padStart(2, '0')}/${yesterday.getDate().toString().padStart(2, '0')}`;
  })()
}}"
        },
        "operation": "getAll",
        "returnAll": true
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "YFARhQXJAjbwXjSO",
          "name": "Vishal Gmail"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "4a8fdfd9-93d7-43a2-92b0-88d845f217bf",
      "name": "Organize Email Data - Morning",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        460,
        0
      ],
      "parameters": {
        "include": "specifiedFields",
        "options": {},
        "aggregate": "aggregateAllItemData",
        "fieldsToInclude": "id, From, To, CC, snippet"
      },
      "typeVersion": 1
    },
    {
      "id": "9e2426e8-57ba-4708-b66f-b58bd19eabff",
      "name": "Summarize Emails with OpenAI - Morning",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        680,
        0
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini",
          "cachedResultName": "GPT-4O-MINI"
        },
        "options": {},
        "messages": {
          "values": [
            {
              "content": "=Go through this email summary and identify all key details mentioned, any specific issues to look at, and action items.
Use this format to output
{
  \"summary_of_emails\": [
    \"Point 1\",
    \"Point 2\",
    \"Point 3\"
  ],
  \"actions\": [
    {
      \"name\": \"Name 1\",
      \"action\": \"Action 1\"
    },
    {
      \"name\": \"Name 1\",
      \"action\": \"Action 2\"
    },
    {
      \"name\": \"Name 2\",
      \"action\": \"Action 3\"
    }
  ]
}

Input Data:

 {{ $json.data.toJsonString() }}

"
            }
          ]
        },
        "jsonOutput": true
      },
      "credentials": {
        "openAiApi": {
          "id": "ksU2WMcMqe2lPgRw",
          "name": "OpenAi account"
        }
      },
      "typeVersion": 1.7
    },
    {
      "id": "4aa68ee8-d38f-418a-9f20-6cc76850c638",
      "name": "Send Summary - Morning",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1040,
        0
      ],
      "webhookId": "83f2aeb9-7b6c-4336-b5ed-8acfcd259850",
      "parameters": {
        "sendTo": "team-email@example.com",
        "message": "=<!DOCTYPE html>
<html lang=\"en\">
<head>
    <meta charset=\"UTF-8\">
    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">
    <title>Email Summary - isbonline@quantana.in</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
            background-color: #f9f9f9;
            color: #333;
            line-height: 1.6;
        }
        .email-container {
            max-width: 600px;
            margin: 20px auto;
            background: #ffffff;
            border: 1px solid #ddd;
            border-radius: 10px;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
        }
        .email-header {
            background-color: #0073e6;
            color: #fff;
            padding: 20px;
            text-align: center;
            border-top-left-radius: 10px;
            border-top-right-radius: 10px;
        }
        .email-header h1 {
            margin: 0;
            font-size: 24px;
        }
        .email-content {
            padding: 20px;
        }
        .section-title {
            font-size: 20px;
            color: #0073e6;
            margin-bottom: 10px;
        }
        ul {
            list-style: none;
            padding: 0;
        }
        ul li {
            margin: 10px 0;
            padding: 10px;
            background: #f4f4f4;
            border-left: 4px solid #0073e6;
            border-radius: 5px;
        }
        .action-item {
            font-weight: bold;
            margin: 5px 0;
        }
        .action-detail {
            margin-left: 10px;
        }
        .email-footer {
            background-color: #0073e6;
            color: #fff;
            text-align: center;
            padding: 10px;
            font-size: 14px;
            border-bottom-left-radius: 10px;
            border-bottom-right-radius: 10px;
        }
    </style>
</head>
<body>
    <div class=\"email-container\">
        <div class=\"email-header\">
            <h1>Email Summary</h1>
        </div>
        <div class=\"email-content\">
            <div>
                <h2 class=\"section-title\">Summary of Emails:</h2>
                <ul>
                    {{ $json.message.content.summary_of_emails.map(email => `<li>${email}</li>`).join('') }}
                </ul>
            </div>
            <div>
                <h2 class=\"section-title\">Actions:</h2>
                <ul>
                    {{ $json.message.content.actions.map(action => `
                        <li>
                            <span class=\"action-item\">${action.name}:</span>
                            <span class=\"action-detail\">${action.action}</span>
                        </li>
                    `).join('') }}
                </ul>
            </div>
        </div>
        <div class=\"email-footer\">
            <p>Generated by Quantana ESAgent <br /> A Quantana AI Labs Initiative
        </div>
    </div>
</body>
</html>",
        "options": {
          "ccList": "cc-list@example.com",
          "appendAttribution": false,
          "replyToSenderOnly": false
        },
        "subject": "=ESAgent - {{ new Date(new Date().setDate(new Date().getDate() - 1)).toLocaleDateString('en-GB', { day: '2-digit', month: 'short', year: 'numeric' }) }}-00:00 to {{ new Date(new Date().setDate(new Date().getDate())).toLocaleDateString('en-GB', { day: '2-digit', month: 'short', year: 'numeric' }) }}-07:00AM"
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "YFARhQXJAjbwXjSO",
          "name": "Vishal Gmail"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "c7667667-9533-40cb-9c09-914a11560600",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        400,
        -132.6641804468672
      ],
      "parameters": {
        "width": 226.7095107678671,
        "height": 305.83657700487913,
        "content": "Organizes the fetched email data, extracting fields like sender, receiver, CC, and a preview snippet."
      },
      "typeVersion": 1
    },
    {
      "id": "43955af4-3a18-44d7-8c8d-cf8051b18bdd",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        980,
        -180
      ],
      "parameters": {
        "width": 232.8435827211592,
        "height": 359.7308639651144,
        "content": "- Sends the summarized email report to recipients with a styled HTML layout.
- Update the \"sendTo\" and \"ccList\" fields with the email addresses of your recipients.

"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "timezone": "Asia/Kolkata",
    "callerPolicy": "workflowsFromSameOwner",
    "executionOrder": "v1"
  },
  "versionId": "b18912ed-6c1f-4912-b75a-1553f7620917",
  "connections": {
    "Daily 7AM Trigger": {
      "main": [
        [
          {
            "node": "Fetch Emails - Past 24 Hours",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Emails - Past 24 Hours": {
      "main": [
        [
          {
            "node": "Organize Email Data - Morning",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Organize Email Data - Morning": {
      "main": [
        [
          {
            "node": "Summarize Emails with OpenAI - Morning",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Summarize Emails with OpenAI - Morning": {
      "main": [
        [
          {
            "node": "Send Summary - Morning",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

功能特点

  • 自动检测新邮件
  • AI智能内容分析
  • 自定义分类规则
  • 批量处理能力
  • 详细的处理日志

技术分析

节点类型及作用

  • Stickynote
  • Scheduletrigger
  • Gmail
  • Aggregate
  • @N8N/N8N Nodes Langchain.Openai

复杂度评估

配置难度:
★★★★☆
维护难度:
★★☆☆☆
扩展性:
★★★★☆

实施指南

前置条件

  • 有效的Gmail账户
  • n8n平台访问权限
  • Google API凭证
  • AI分类服务订阅

配置步骤

  1. 在n8n中导入工作流JSON文件
  2. 配置Gmail节点的认证信息
  3. 设置AI分类器的API密钥
  4. 自定义分类规则和标签映射
  5. 测试工作流执行
  6. 配置定时触发器(可选)

关键参数

参数名称 默认值 说明
maxEmails 50 单次处理的最大邮件数量
confidenceThreshold 0.8 分类置信度阈值
autoLabel true 是否自动添加标签

最佳实践

优化建议

  • 定期更新AI分类模型以提高准确性
  • 根据邮件量调整处理批次大小
  • 设置合理的分类置信度阈值
  • 定期清理过期的分类规则

安全注意事项

  • 妥善保管API密钥和认证信息
  • 限制工作流的访问权限
  • 定期审查处理日志
  • 启用双因素认证保护Gmail账户

性能优化

  • 使用增量处理减少重复工作
  • 缓存频繁访问的数据
  • 并行处理多个邮件分类任务
  • 监控系统资源使用情况

故障排除

常见问题

邮件未被正确分类

检查AI分类器的置信度阈值设置,适当降低阈值或更新训练数据。

Gmail认证失败

确认Google API凭证有效且具有正确的权限范围,重新进行OAuth授权。

调试技巧

  • 启用详细日志记录查看每个步骤的执行情况
  • 使用测试邮件验证分类逻辑
  • 检查网络连接和API服务状态
  • 逐步执行工作流定位问题节点

错误处理

工作流包含以下错误处理机制:

  • 网络超时自动重试(最多3次)
  • API错误记录和告警
  • 处理失败邮件的隔离机制
  • 异常情况下的回滚操作